package com.li;

import java.util.ArrayList;
import java.util.List;

public class PlateSimilarity {

    public static void main(String[] args) {
        String a = "豫A3366X";
        String b = "豫A7655X";
        System.out.println(plateSimilarity(a,b));
    }

    public  static float plateSimilarity(String plateA,String plateB ){
        float plateSimilar=0;
        float plateSimilarTemp=0;
        List<String> splitPlateAList = splitPlate(plateA);
        List<String> splitPlateBList = splitPlate(plateB);
        //外循环车牌A切割后集合,内循环车牌B切割后集合,判断是否有相同字符串，判断相似度
        for (String strA : splitPlateAList
        ) {
            for (String strB:splitPlateBList
            ) {
                if(strA.equals(strB)){
                    plateSimilarTemp=strA.length()/(float)plateA.length();
                    if(plateSimilar<plateSimilarTemp){
                        plateSimilar=plateSimilarTemp;
                    }
                    System.out.println("相似片段:"+strA);
                }
            }
        }
        return plateSimilar;
    }


    public static List<String> splitPlate(String plate) {
        List<String> splitPlateList = new ArrayList<>();
        for (int iIndex = 0; iIndex < plate.length(); iIndex++) {
            for (int jIndex = iIndex + 1; jIndex <= plate.length(); jIndex++) {
                splitPlateList.add(plate.substring(iIndex, jIndex));
            }
        }
        return splitPlateList;
    }
}
